<?php

namespace myshop\common\dao;

use longhu\exceptions\ValidateFailedException;
use myshop\common\validate\admin\CreateAdminApiLog;
use think\db\BaseQuery;
use think\facade\Db;

class AdminApiLogDao
{
    public function setModel():string
    {
        return 'admin_api_';
    }

    public function getModel(string $type = ''):BaseQuery
    {
        $tableName  = empty($type)?$this->setModel():$this->setModel().$type.'_log';
        return Db::connect('mongo')->name($tableName);
    }

    /**
     * @param string $type
     * @param array $data
     * @return int|string
     */
    public function createData(string $type = '',array $data = [])
    {
        $validate = new CreateAdminApiLog();
        if(!$validate->check($data)){
            throw new ValidateFailedException($validate->getError());
        };
       return $this->getModel($type)->save($data);
    }

    public function deleteById(string $id)
    {

    }




}